Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repo-level policy guide and enhance cyral_rego_policy_instance docs #495

Merged
merged 9 commits into from
Jan 19, 2024

Conversation

gabfelp
Copy link
Contributor

@gabfelp gabfelp commented Jan 18, 2024

Description of the change

We are adding a new type of built in template named dataset-protection + Adding a guide with examples for each one of the policies

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • Jira issue referenced in commit message and/or PR title

Testing

Tests we executed with the examples from the guide:

Defined cyral in the providers.tf file

After that, we created a file named "resource.tf", with the following content:

resource "cyral_repository" "repo" {
  type = "mysql"
  name = "GABRIEL_MYSQL_REGO"

  repo_node {
    host = "mysql.cyral.com"
    port = 3306
  }
}

# Creates pg data repository
resource "cyral_repository" "repo2" {
  type = "postgresql"
  name = "my_pg"

  repo_node {
    host = "pg.cyral.com"
    port = 5432
  }
}

# create policy instance from template
resource "cyral_rego_policy_instance" "policy0" {
  name        = "data-firewall-policy"
  category    = "SECURITY"
  description = "Filter 'finance.cards' when someone (except 'Admin' group) reads it"
  template_id = "data-firewall"
  parameters  = "{ \"dataSet\": \"finance.cards\", \"dataFilter\": \" finance.cards.country = 'US' \", \"labels\": [\"CCN\"], \"excludedIdentities\": { \"groups\": [\"Admin\"] } }"
  enabled     = true
  scope {
    repo_ids = [cyral_repository.repo2.id]
  }
  tags = ["tag1", "tag2"]
}

# create policy instance from template
resource "cyral_rego_policy_instance" "policy1" {
  name        = "data-masking-policy"
  category    = "SECURITY"
  description = "Masks label CCN for identities in Marketing group"
  template_id = "data-masking"
  parameters  = "{ \"maskType\": \"NULL_MASK\", \"labels\": [\"CCN\"], \"identities\": { \"included\": { \"groups\": [\"Marketing\"] } }}"
  enabled     = true
  scope {
    repo_ids = [cyral_repository.repo.id]
  }
  tags = ["tag1", "tag2"]
}

# create policy instance from template
resource "cyral_rego_policy_instance" "policy2" {
  name        = "data-protection-policy"
  category    = "SECURITY"
  description = "Protect label CCN for update and delete queries"
  template_id = "data-protection"
  parameters  = "{ \"block\": true, \"alertSeverity\": \"high\", \"monitorUpdates\": true, \"monitorDeletes\": true, \"labels\": [\"CCN\"]}"
  enabled     = true
  scope {
    repo_ids = [cyral_repository.repo.id]
  }
  tags = ["tag1", "tag2"]
}

 create policy instance from template
 resource "cyral_rego_policy_instance" "policy3" {
   name        = "dataset-protection"
   category    = "SECURITY"
   description = "Blocks reads and updates over schema 'finance' and dataset 'cyral.customers'."
   template_id = "dataset-protection"
   parameters  = "{ \"block\": true, \"alertSeverity\": \"high\", \"monitorUpdates\": true, \"monitorReads\": true, \"datasets\": {\"disallowed\": [\"finance.*\", \"cyral.customers\"]}}"
   enabled     = true
   scope {
     repo_ids = [cyral_repository.repo2.id]
   }
 }

# create policy instance from template
resource "cyral_rego_policy_instance" "policy4" {
  name        = "rate-limit-policy"
  category    = "SECURITY"
  description = "Implement a threshold on label CCN for group Marketing of 500 rows per hour"
  template_id = "rate-limit"
  parameters  = "{ \"rateLimit\": 500, \"block\": true, \"alertSeverity\": \"high\", \"labels\": [\"CCN\"], \"identities\": { \"included\": { \"groups\": [\"Marketing\"] } }}"
  enabled     = true
  scope {
    repo_ids = [cyral_repository.repo2.id]
  }
  tags = ["tag1", "tag2"]
}

# create policy instance from template
resource "cyral_rego_policy_instance" "policy5" {
  name        = "read-limit-policy"
  category    = "SECURITY"
  description = "Limits to 100 the amount of rows that can be read per query on all repository data for group 'Devs'"
  template_id = "read-limit"
  parameters  = "{ \"rowLimit\": 100, \"block\": true, \"alertSeverity\": \"high\", \"appliesToAllData\": true, \"identities\": { \"included\": { \"groups\": [\"Devs\"] } }}"
  enabled     = true
  scope {
    repo_ids = [cyral_repository.repo2.id]
  }
}


resource "cyral_rego_policy_instance" "policy6" {
  name        = "repository-protection-policy"
  category    = "SECURITY"
  description = "Limits to 100 the amount of rows that can be updated or deleted per query on all repository data for anyone except group 'Admin'"
  template_id = "repository-protection"
  parameters  = "{ \"rowLimit\": 100, \"block\": true, \"alertSeverity\": \"high\", \"monitorUpdates\": true, \"monitorDeletes\": true, \"identities\": { \"excluded\": { \"groups\": [\"Admin\"] } }}"
  enabled     = true
  scope {
    repo_ids = [cyral_repository.repo.id]
  }
}

resource "cyral_rego_policy_instance" "policy7" {
  name        = "service account abuse policy"
  category    = "SECURITY"
  description = "Always require user attribution for service acount 'john'"
  template_id = "service-account-abuse"
  parameters  = "{ \"block\": true, \"alertSeverity\": \"high\", \"serviceAccounts\": [\"john\"]}"
  enabled     = true
  scope {
    repo_ids = [cyral_repository.repo2.id]
  }
}

resource "cyral_rego_policy_instance" "policy8" {
  name        = "user-segmentation-policy"
  category    = "SECURITY"
  description = "Applies a data filter in 'finance.cards' when someone from group 'Marketing' reads data labeled as 'CCN'"
  template_id = "user-segmentation"
  parameters  = "{ \"dataSet\": \"finance.cards\", \"dataFilter\": \" finance.cards.country = 'US' \", \"labels\": [\"CCN\"], \"includedIdentities\": { \"groups\": [\"Marketing\"] } }"
  enabled     = true
  scope {
    repo_ids = [cyral_repository.repo.id]
  }
  tags = ["tag1", "tag2"]
}

When we run terraform plan:
image

terraform apply:
image

terraform show:
image

Now in the UI:
image
image

It also shows in the UI:
image

@gabfelp gabfelp requested a review from wcmjunior January 18, 2024 18:08
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@wcmjunior wcmjunior changed the title Add guides for rego policy instances + enhance cyral_rego_policy_instance docs Add repo-level policy guide and enhance cyral_rego_policy_instance docs Jan 19, 2024
@wcmjunior wcmjunior merged commit cd3f3de into main Jan 19, 2024
2 checks passed
@wcmjunior wcmjunior deleted the docs/table-level-policy branch January 19, 2024 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants